import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Login extends JPanel{
	private static final long serialVersionUID = 1L;
	
	private JTextField loginField;
	private JTextField passwordField;
	private JLabel lblMessageErreur;


	/**
	 * Create the application.
	 */
	public Login() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		
		
		JLabel lblLogin = new JLabel("Login:");
		
		JLabel lblPassword = new JLabel("Password:");
		
		lblMessageErreur = new JLabel();
		loginField = new JTextField();
		loginField.setColumns(25);
		
		passwordField = new JTextField();
		passwordField.setColumns(25);
		
		JButton btnConnexion = new JButton("Connexion");
		btnConnexion.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				 connexionButtonAction();
			}
		});
		
		GroupLayout gl_panel = new GroupLayout(this);
		
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addComponent(lblMessageErreur, Alignment.CENTER)
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(71)
							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addComponent(lblLogin)
								.addComponent(lblPassword))
							.addGap(25)
							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
								.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(loginField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_panel.createSequentialGroup()
							.addGap(133)
							.addComponent(btnConnexion)))
					.addContainerGap(103, Short.MAX_VALUE))
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addGap(58)
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addComponent(loginField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(lblLogin))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
						.addComponent(lblPassword)
						.addComponent(passwordField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(32)
					.addComponent(btnConnexion)
					.addGap(32)
					.addComponent(lblMessageErreur)
					.addContainerGap(97, Short.MAX_VALUE))
		);
		this.setLayout(gl_panel);
		
	}
	private void connexionButtonAction(){
			lblMessageErreur.setText(Controler.getControler().verifierConnexion(this.loginField.getText(), this.passwordField.getText()));		
	}
}
